package com.yyds.blackmagic.controller;


import com.yyds.blackmagic.entity.Category;
import com.yyds.blackmagic.service.CategoryService;
import com.yyds.blackmagic.vo.ActionResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yj
 * @description
 * @date
 */
@RestController
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/categorys")
    public ActionResult findAll(){
        List<Category> all = categoryService.findAll();
        return new ActionResult(200,"以查询到所有内容",all);
    }

    @GetMapping("/category/{id}")
    public ActionResult findOne(@PathVariable("id") int id){
        Category one = categoryService.findOne(1);
        return new ActionResult(200,"查询到指定内容",one);
    }

    @PutMapping("/category")
    public ActionResult updateCategory(@RequestBody Category category){
        Category category1 = categoryService.updateCategory(category);
        return new ActionResult(200,"修改成功",category1);
    }


    @DeleteMapping("/category")
    public ActionResult deleteCategory(@RequestBody int id){
        boolean b = categoryService.deleteCategory(1);
        return new ActionResult(200,"删除成功",b);
    }

    @PutMapping("/category1")

    @PostMapping("/category1")
    public ActionResult addCategory(@RequestBody Category category){
        Category category1 = categoryService.addCategory(category);
        return new ActionResult(200,"添加成功",category1);
    }
}
